/*
 * ===================================================
 *
 *       Filename:  utils.c
 *
 *
 *        Created:  10/18/2011 06:30:41 PM
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  durand_y, <durand.yoan@gmail.com>
 *
 * ===================================================
 */
#include "utils.h"


float           my_pow(int     a,
                       int     b)
{
  int           p;
  float         res;

  p = 1;
  res = a;

  if(b > 0)
  {
    while (b > p)
    {
      res *= a;
      p++;
    }
  }
  else
  {
    b = (b * (-1));
    while (b > p)
    {
      res *= a;
      p++;
    }
    res = (1 / res);
  }

  return (res);
}

int     fact(int    n)
{
  int   res = 1;

  if (n < 0)
    return (-1);
  while (n > 0)
  {
    res *= n;
    n--;
  }
  return (res);
}
